import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text("Select Box Demo"),
      ),
      body: SwitchAndCheckBoxWidget(),
    ),
  ));
}

class SwitchAndCheckBoxWidget extends StatefulWidget {
  @override
  _SwitchAndCheckBoxWidgetState createState() =>
      _SwitchAndCheckBoxWidgetState();
}

class _SwitchAndCheckBoxWidgetState extends State<SwitchAndCheckBoxWidget> {
  bool _switchRadio = true;
  bool _switchCheckBox = true;

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      Row(children: [
        const Text('打开设置', style: TextStyle(fontSize: 25.0),),
        Switch(
          value: _switchRadio,
          onChanged: (value) {
            setState(() => _switchRadio = value);
          },
        ),
      ]),
      Row(children: [
        const Text('已选中', style: TextStyle(fontSize: 25.0),),
        Checkbox(
          value: _switchCheckBox,
          activeColor: Colors.red,
          onChanged: (value) {
            setState(() => _switchCheckBox = value!);
          },
        )
      ],),
    ]);
  }
}
